import { DefaultAvatar } from '../../models/index.js';

export async function seedDefaultAvatars() {
  try {
    // 默认头像配置
    const defaultAvatars = [
      {
        name: '默认男性头像1',
        url: 'uploads/default-avatars/male-1.png',
        category: 'male',
        sort: 100,
        status: 'active'
      },
      {
        name: '默认男性头像2',
        url: 'uploads/default-avatars/male-2.png',
        category: 'male',
        sort: 90,
        status: 'active'
      },
      {
        name: '默认女性头像1',
        url: 'uploads/default-avatars/female-1.png',
        category: 'female',
        sort: 100,
        status: 'active'
      },
      {
        name: '默认女性头像2',
        url: 'uploads/default-avatars/female-2.png',
        category: 'female',
        sort: 90,
        status: 'active'
      },
      {
        name: '默认卡通头像1',
        url: 'uploads/default-avatars/cartoon-1.png',
        category: 'cartoon',
        sort: 100,
        status: 'active'
      }
    ];

    // 检查是否已存在默认头像
    const existingAvatar = await DefaultAvatar.findOne();
    
    if (!existingAvatar) {
      // 创建默认头像
      await DefaultAvatar.bulkCreate(defaultAvatars);
      console.log('默认头像创建成功！');
      console.log('已创建以下头像：');
      defaultAvatars.forEach(avatar => {
        console.log(`- ${avatar.name} (${avatar.category})`);
      });
    } else {
      console.log('默认头像已存在，跳过创建。');
    }
  } catch (error) {
    console.error('创建默认头像失败:', error);
    throw error;
  }
}

export default seedDefaultAvatars;
